# Definition for a binary tree node.
# class TreeNode:
#     def __init__(self, val=0, left=None, right=None):
#         self.val = val
#         self.left = left
#         self.right = right
class Solution:
    def isValidBST(self, root: Optional[TreeNode], left=None, right=None) -> bool:
        if root.left:
            if root.left.val >= root.val:
                return False
            if left and root.left.val <= left:
                return False                
            if not self.isValidBST(root.left, left=left, right=root.val):
                return False
        if root.right:
            if root.right.val <= root.val:
                return False
            if right and root.right.val >= right:
                return False
            if not self.isValidBST(root.right, left=root.val, right=right):
                return False
        return True
